<template>
  <div>
    <div class="logbook">
      <el-backtop target=".el-main" :bottom="100" :right="100" ref="backtop" />
      <div class="logbookspace">
        <el-space>
          <el-input
            v-model.trim="targetAdminId"
            @keyup.enter="logbook()"
            placeholder="请输入用户ID"
          />
          <el-button
            type="primary"
            class="iconfont icon-sousuo"
            @click="logbook()"
            >查找</el-button
          >
        </el-space>
      </div>
      <div class="box2">
        <el-table :data="tableData" border class="shars">
          <el-table-column prop="id" label="日志ID" width="220" />
          <el-table-column prop="adminId" label="管理员ID" width="220" />
          <el-table-column prop="requestId" label="请求ID" width="220" />
          <el-table-column prop="group" label="API分组" width="220" />
          <el-table-column prop="method" label="API方法" width="220" />
          <el-table-column prop="gmtCreate" label="操作时间" width="220">
            <template #default="scope">
              {{ new Date(scope.row.gmtCreate).friendtTime() }}
            </template>
          </el-table-column>
        </el-table>
      </div>
      <PagLnatio
        v-bind="paging"
        @handleCurrentChange="handleCurrentChange"
        @handleSizeChange="handleSizeChange"
      ></PagLnatio>
    </div>
  </div>
</template>

<script>
import PagLnatio from "@/components/PagLnatio.vue";
import http from "@/http";
import { ElMessage as $msg } from "element-plus";
export default {
  components: {
    PagLnatio,
  },
  data() {
    return {
      tableData: [],
      targetAdminId: "", //管理员id
      paging: {
        page: 1, //默认第一页
        limit: 10, //显示几页
        total: null,
      },
    };
  },
  created() {
    this.logbook();
  },
  methods: {
    logbook() {
      let data = {
        _gp: "admin.log",
        _mt: "list",
        limit: this.paging.limit,
        page: this.paging.page,
        targetAdminId: this.targetAdminId,
      };
      http.post(data).then((res) => {
        console.log(res);
        if (200 == res.errno) {
          this.tableData = res.data.items;
          this.paging.total = res.data.count;
        }
      });
    },
    handleSizeChange(val) {
      console.log(val);
      this.paging.limit = val;
      this.logbook();
    },
    handleCurrentChange(val) {
      this.paging.page = val;
      this.logbook();
    },
  },
};
</script>

<style lang="less" scope>
.logbook {
  width: 98%;
  margin: auto;
  .logbookspace {
    height: 40px;
  }
}
</style>
